/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { Modal } from 'antd';
import React, { useState } from 'react';
import styles from './index.less';

interface LinkModalProps {
  to: string;
  width?: number;
}

const LinkModal: React.FC<LinkModalProps> = (props) => {
  const { to, width } = props;
  const [open, setOpen] = useState(false);

  const handleClick = (e: any) => {
    e.stopPropagation();
    e.preventDefault();
    setOpen(true);
  };

  const handleClose = () => setOpen(false);

  return (
    <>
      <span onClick={handleClick}>{props.children}</span>
      <Modal
        width={width}
        maskClosable
        open={open}
        onCancel={handleClose}
        className={styles.linkModal}
        centered
        footer={null}
      >
        <iframe src={to}></iframe>
      </Modal>
    </>
  );
};

export default LinkModal;
